<html>
<head>
    <title>水费读数修改</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../assets/css/dpl-min.css" rel="stylesheet" type="text/css" />
    <link href="../assets/css/bui-min.css" rel="stylesheet" type="text/css" />
    <link href="../assets/css/page-min.css" rel="stylesheet" type="text/css" />   <!-- 下面的样式，仅是为了显示代码，而不应该在项目中使用-->
    <link href="../assets/css/prettify.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        code {
            padding: 0px 4px;
            color: #d14;
            background-color: #f7f7f9;
            border: 1px solid #e1e1e8;
        }
    </style>
</head>
<body>

<div class="container">
    <form id ="J_Form" class="form-horizontal" action="success.html">
        <div class="row">
            <div class="control-group span12">
                <label class="control-label"><s>*</s>水表读数：</label>
                <div class="controls">
                    <input name="readNum" type="text" class="control-text" data-rules="{required:true}" style="width:300px;">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="form-actions offset3">
                <button type="button" class="button button-primary" id="saveBtn">保存</button>
            </div>
        </div>

        <input type="text" name="id" style="display: none;" />
    </form>
</div>
<script type="text/javascript" src="../assets/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="../assets/js/bui-min.js"></script>
<script type="text/javascript" src="../assets/js/ajaxfileupload.js"></script>


<script type="text/javascript" src="../assets/js/config-min.js"></script>

<script type="text/javascript">
    BUI.use('common/page');
</script>
<script type="text/javascript">
    BUI.use('bui/form',function (Form) {
        var form = new Form.HForm({
            srcNode : '#J_Form'
        }).render();
    });

    var id = getQueryString("id");
    console.log(id);
    if( id != null) {
        $('[name="id"]').val(id);
        $.ajax({
            url: "/backend/waterBills/edit/"+id,
            dataType: "json",
            type:"get",
            data: {},
            success: function (data) {
                data = data.data;
                $('[name="readNum"]').val(data.multiReadNum);
            }
        });
    }

    $("#saveBtn").click(function(){
        var id = getQueryString("id");
        console.log("saveBtn>>>>"+id);
        var url = "/backend/waterBills/update";
        var readNum = $('[name="readNum"]').val();

        var data = {
            "id":id,
            "readNum":readNum
        };
        $.ajax({
            url:url,
            dataType:"json",
            contentType:"application/json;charset=utf-8",
            type:"post",
            data:JSON.stringify(data),
            success: function(data){
                console.log(data);
                if( data.rc === 1){
                    if(id === null){
                        location.href = "/page/waterBills";
                    }else{
                        top.topManager.openPage({
                            id : 'waterBills',
                            isClose : true,
                            reload : true
                        });
                    }
                }
            }
        });
    });

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }


</script>


</body>
</html>